import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    loginFlag: false,
    forgetFlag: false,
    loginUrl: "",
    userId: null,
    avatar: null,
    username: null,
    loginType: null,
  },
  mutations: {
    login(state, user) {
      state.username = user;
    },
    logout(state) {
      state.username = null;
    },
    saveLoginUrl(state, url) {
      state.loginUrl = url;
    },
    closeModel(state) {
      state.registerFlag = false;
      state.loginFlag = false;
      state.searchFlag = false;
      state.emailFlag = false;
    },
  },
  actions: {},
  modules: {},
  plugins: [
    createPersistedState({
      storage: window.sessionStorage
    })
  ]
});
